package com.zd.login.controller;

import com.zd.model.Teacher;
import com.zd.login.service.LoginService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        System.out.println(username+"YYY"+password);
        LoginService loginService=new LoginService();
        /*由service层处理*/
        Teacher teacher= loginService.checkLogin(username, password);
        //表示登陆过
        if (teacher!=null){
            //如果登录成功，进去学生列表界面
            //设置session过期的时间20分钟，老师
            request.getSession().setAttribute("userInfo",teacher);
            request.getRequestDispatcher("WEB-INF/view/studentlist.jsp").forward(request,response);
        }else{
            request.getRequestDispatcher("login.jsp").forward(request,response);
        }
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
